import {View } from "@tarojs/components";
import {useState} from "react";
import Taro from "@tarojs/taro";
import './index.scss'


//获取当前日期，并生成最近十四天的日期
const getDat = ()=>{
  //获取当天的日期
  const toDay = Date.now();
  console.log('今天日期',toDay,new Date(toDay))
  //获取今天是周几
  const weeked = new Date(toDay).getDay()
  console.log('今天是星期',weeked)
  //获取星期天开始的第一天
  const firstDay = toDay-(86400000*weeked)
  let listDay  = []
  for (let i=0;i<14;i++){
    const aaa:number = new Date(firstDay+(86400000*i)).getDate()
    listDay.push(aaa)
  }
  console.log(listDay)
  return listDay

}
function Index() {
  //今天
  const today  = new Date(Date.now()).getDate()
  console.log('today',today)
  //设置上下来拉的箭头
  const [isUp,setUp] = useState(true)
  const setUpHandler =(height)=>{
    console.log('dianji')
    setUp(!isUp)
    setCalendarH(height)
  }
  //控制日历展示的高度
  const [calendarH,setCalendarH] = useState(60)
  const [dayList1,setDayList1] = useState(getDat().splice(0 ,7))
  const [dayList2,setDayList2] = useState(getDat().splice(7 ,7))

  return (
    <View>
      <View style={{backgroundColor:'#fff',height:'80px',lineHeight:'80px'}}>
        <View style={{position:'absolute',top:'0',left:'0',fontSize:'22px',paddingTop:'6px',display:'flex'}}
              onClick={()=>Taro.navigateBack()}>
          <View style={{fontSize:'16px',paddingLeft:'10px',fontWeight:600}}>日程</View>
        </View>
        <View style={{textAlign:'center',width:'100%'}}></View>
      </View>
    <View className='box'>
      <View className='view' style={{height:calendarH+'px'}}>
        <View className='day'>
          <View>日</View>
          <View>一</View>
          <View>二</View>
          <View>三</View>
          <View>四</View>
          <View>五</View>
          <View>六</View>
        </View>
        <View className='dayList'>
          <View  className='dayItem'>{dayList1.map((item)=><View className='item' style={{color:today>item?'#ccc':''}}>{item}<View className='dian' style={{display:today>item?'none':'block'}}></View></View>)}</View>
          <View  className='dayItem'>{dayList2.map((item)=><View className='item'>{item}<View className='dian'></View></View>)}</View>
        </View>
      </View>
      <View className='downUp'>
        <View className='iconfont icon-xiangxia' onClick={()=>setUpHandler(100)} style={{display:isUp?'block':'none'}}></View>
        <View className='iconfont icon-xiangshang' onClick={()=>setUpHandler(60)}  style={{display:!isUp?'block':'none'}}></View>
      </View>
      <View className='dateTime'>今天</View>
      <View className='list'>
        <View className='item'>
          <View className='time'>10:00</View>
          <View className='context'>
            <View className='name'>肩颈按摩</View>
            <View className='adders'>地点：xxx区xx路xx号xx小区xx单元xxx室</View>
          </View>
        </View>
        <View className='item'>
          <View className='time'>10:00</View>
          <View className='context'>
            <View className='name'>肩颈按摩</View>
            <View className='adders'>地点：xxx区xx路xx号xx小区xx单元xxx室</View>
          </View>
        </View>
        <View className='item'>
          <View className='time'>10:00</View>
          <View className='context'>
            <View className='name'>肩颈按摩</View>
            <View className='adders'>地点：xxx区xx路xx号xx小区xx单元xxx室</View>
          </View>
        </View>
      </View>
    </View>

    </View>
  )
}

export default Index;
